from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton
from PyQt6.QtCore import Qt


class PatternPreviewPage(QWidget):
    """图案预览页面"""

    def __init__(self, parent=None):
        super().__init__(parent)
        self.init_ui()

    def init_ui(self):
        """初始化页面布局"""
        layout = QVBoxLayout(self)
        layout.setContentsMargins(20, 20, 20, 20)
        layout.setSpacing(20)

        # 页面标题
        title_label = QLabel("图案预览")
        title_label.setStyleSheet("font-size: 24px; font-weight: bold;")
        title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        layout.addWidget(title_label)

        # 图案显示区域
        self.pattern_label = QLabel("图案将在这里显示")
        self.pattern_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.pattern_label.setStyleSheet("""
            background-color: white;
            border: 2px solid #ccc;
            border-radius: 5px;
            padding: 20px;
            min-height: 300px;
            font-size: 16px;
        """)
        layout.addWidget(self.pattern_label)

        # 关闭按钮
        close_btn = QPushButton("关闭预览")
        close_btn.clicked.connect(self.close)
        layout.addWidget(close_btn, alignment=Qt.AlignmentFlag.AlignCenter)

        self.setLayout(layout)

    def set_pattern(self, pattern: str, modes: list):
        """设置图案预览"""
        self.pattern_label.setText(f"图案类型: {pattern}\n拼摆方式: {', '.join(modes)}")